WGQuery.prototype = Array.prototype;


function WGQuery(arg) {

    if (typeof arg == "string") {
        var eles = document.querySelectorAll(arg);
        for (var i = 0; i < eles.length; i++) {
            this.push(eles[i]);
        }
    } else if (typeof arg == "object") {
        this.push(arg);
    } else if (typeof arg == "function") {

        document.addEventListener('DOMContentLoaded', function() {
            arg();
        });

    }


}


function $(arg) {
    return new WGQuery(arg);
}



WGQuery.prototype.css = function() {
console.log(arguments);
    if (arguments.length == 1) {

        var arg = arguments[0];

        if (typeof arg == "string") {
            return getComputedStyle(this[0])[arg];
        } 

        if (typeof arg == "object") {
            this.forEach(function(ele, i) {

                for (key in arg) {
                    if (typeof arg[key] == 'string') {
                        ele.style[key] = arg[key];
                    }
                    if (typeof arg[key] == 'function') {
                        ele.style[key] = arg[key](i);
                    }
                    
                }

            });
            return this;
        }


    } else if (arguments.length == 2) {

        // 第一个参数, height
        var arg1 = arguments[0];
        // 第二个参数, 200px
        var arg2 = arguments[1];

        if (typeof arg2 == 'string') {
            this.forEach(function(ele) {
                ele.style[arg1] = arg2;
            });
        } else if (typeof arg2 == 'function') {
            this.forEach(function(ele, i) {
                ele.style[arg1] = arg2(i);
            });
        }   

        // 链式操作返回this
        return this;
    }

};




// 点击事件
WGQuery.prototype.click = function(func) {

    this.forEach(function(ele, i) {

        ele.onclick = function(e) {

            func.call(this, e);
        };

    });

    return this;
};














